import {defineConfig, loadEnv} from 'vite'
import { resolve } from 'path';
import {URL, fileURLToPath} from 'node:url'
import createVitePlugins from "./config";
import process from "node:process";
// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
    const env = loadEnv(mode, process.cwd()) as ImportMetaEnv
    return {
        /**desc 服务器选项 https://cn.vitejs.dev/config/#server-options **/
        server: {
            open:true,
            port: Number(env.VITE_APP_PORT ?? 5173),
        },
        /**desc 构建选项 https://cn.vitejs.dev/config/build-options.html **/
        build:{
            outDir:'dist',
            sourcemap: false,
        },
        /**路径别名**/
        resolve: {
            alias: {
                '~': fileURLToPath(new URL('./', import.meta.url)),
                '@': fileURLToPath(new URL('./src', import.meta.url)),
                'assets': fileURLToPath(new URL('./assets', import.meta.url)),
            },
        },
        /**引入less全局样式变量**/
        css: {
            preprocessorOptions: {
                less: {
                    modifyVars: {
                        hack: `true; @import (reference) "${resolve(
                            'src/assets/style/breakpoint.less'
                        )}";`,
                    },
                    javascriptEnabled: true,
                },
            },
        },
        /**添加需要vite优化的依赖 **/
        optimizeDeps: {
            include: ['vue-draggable-plus'],
        },
        plugins: createVitePlugins(env,command === 'build'),
    }
})
